#include<iostream>
#include<string>
#include<cstdio>
#include<unistd.h>
#include<pthread.h>

using namespace std;

// 1. 测试一个进程创建多个线程，其多个线程的pid是否相同

int x = 100;

void show(const string&name)
{
    cout<<name<<",pid"<<getpid()<<"  "<<x<<"\n"<<endl;
}

void*threadRun(void*args)
{
    const string name = (char*)args;
    while(true)
    {
        show(name);
        sleep(1);
    }
}

int main()
{
    pthread_t tid[5];
    char name[64];
    //在该进程下同时创建5个线程
    for(int i =0;i<5;i++)
    {
        snprintf(name,sizeof name,"%s-%d","thread:",i);
        pthread_create(tid+i,nullptr,threadRun,(void*)name);
        sleep(1);
    }

    while(true)
    {
        cout<<"main thread , pid :"<<getpid()<<endl;
    }
    return 0;
}

